package com.medicine.manage.service.impl;

import java.util.List;
import com.medicine.common.utils.DateUtils;
import com.medicine.common.utils.SecurityUtils;
import com.medicine.manage.block.service.IBlockProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import com.medicine.manage.mapper.SoakingMapper;
import com.medicine.manage.domain.Soaking;
import com.medicine.manage.service.ISoakingService;

/**
 * 煎药Service业务层处理
 * 
 * @author admin
 * @date 2024-10-13
 */
@Service
public class SoakingServiceImpl implements ISoakingService 
{
    @Autowired
    private SoakingMapper soakingMapper;

    @Autowired
    @Qualifier("blockProcessSoakingService")
    private IBlockProcessService blockProcessSoakingService;

    /**
     * 查询煎药
     * 
     * @param id 煎药主键
     * @return 煎药
     */
    @Override
    public Soaking selectSoakingById(Long id)
    {
        return soakingMapper.selectSoakingById(id);
    }

    /**
     * 查询煎药列表
     * 
     * @param soaking 煎药
     * @return 煎药
     */
    @Override
    public List<Soaking> selectSoakingList(Soaking soaking)
    {
        return soakingMapper.selectSoakingList(soaking);
    }

    /**
     * 新增煎药
     * 
     * @param soaking 煎药
     * @return 结果
     */
    @Override
    public int insertSoaking(Soaking soaking)
    {
        soaking.setCreateBy(SecurityUtils.getLoginUser().getUserId().toString());
        soaking.setCreateTime(DateUtils.getNowDate());
        int result = soakingMapper.insertSoaking(soaking);
        blockProcessSoakingService.insertProcessObj(soaking, SecurityUtils.getLoginUser().getDeptId(), SecurityUtils.getLoginUser().getUserId());
        return result;
    }

    /**
     * 修改煎药
     * 
     * @param soaking 煎药
     * @return 结果
     */
    @Override
    public int updateSoaking(Soaking soaking)
    {
        soaking.setUpdateBy(SecurityUtils.getLoginUser().getUserId().toString());
        soaking.setUpdateTime(DateUtils.getNowDate());
        int result = soakingMapper.updateSoaking(soaking);
        Soaking s = soakingMapper.selectSoakingById(soaking.getId());
        blockProcessSoakingService.updateProcessObj(s, SecurityUtils.getLoginUser().getDeptId(), SecurityUtils.getLoginUser().getUserId());
        return result;
    }

    /**
     * 批量删除煎药
     * 
     * @param ids 需要删除的煎药主键
     * @return 结果
     */
    @Override
    public int deleteSoakingByIds(Long[] ids)
    {
        return soakingMapper.deleteSoakingByIds(ids);
    }

    /**
     * 删除煎药信息
     * 
     * @param id 煎药主键
     * @return 结果
     */
    @Override
    public int deleteSoakingById(Long id)
    {
        return soakingMapper.deleteSoakingById(id);
    }
}
